﻿using MediatR;
using U.B.DoMain;
using U.B.ErrorCode;
using U.B.ReadApi.Command;
using U.B.Repistory;

namespace U.B.ReadApi.CommandHander
{
    public class UserAllCommandHander : IRequestHandler<UserAllCommand, ApiResult<User>>
    {
        private readonly IRepistory<User> _userAllRepository;
        public UserAllCommandHander(IRepistory<User> userAllRepository)
        {
            _userAllRepository = userAllRepository;
        }
        /// <summary>
        /// 用户显示
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public Task<ApiResult<User>> Handle(UserAllCommand request, CancellationToken cancellationToken)
        {
            ApiResult<User> result = new ApiResult<User>();
            result.code = Renum.显示成功;
            result.Message = Renum.显示成功.ToString();
            var list = _userAllRepository.GetAll().FirstOrDefault(x => x.UserId == request.UserId);
            result.Data = list;
            return Task.FromResult(result);
        }
    }
}
